<?php
namespace Controller;

use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Container;
use Intervention\Image\ImageManagerStatic as Image;


class SettingApi extends Base
{

    public function __construct(Container $container)
    {
        parent::__construct($container);

        if ($this->getaccount() === false) {
            header("HTTP/1.1 400 Bad Request");
            echo 'no account error';
            exit;
        } else {
            $this->account = $this->getaccount();
        }

    }


    public function setting(Request $req, Response $res)
    {
        $winning = $req->getParam('winning');
        $min = $req->getParam('min');
        $max = $req->getParam('max');
        if ($this->checkfrom->regex('number', $winning) === false) {
            return $res->withStatus(400)->write('中奖概率格式错误');
            exit;
        }
        if ($this->checkfrom->regex('number', $min) === false&&$this->checkfrom->regex('number', $max) === false) {
            return $res->withStatus(400)->write('签到积分格式错误');
            exit;
        }
        $this->redis->set('winning',$winning);
        $this->redis->set('min',$min);
        $this->redis->set('max',$max);
        return $res->withStatus(200)->write('设置成功');
        exit;

    }

}